package com.niit;

import com.niit.entity.Category;
import com.niit.entity.Student;
import com.niit.mapper.CategoryMapper;
import com.niit.mapper.StudentMapper;
import com.niit.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

public class TestFlushCache {
    public static void main(String[] args) {
        SqlSession sqlSession = MybatisUtil.getSqlSession();
        StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);

        Student student1 = studentMapper.getById("111"); // 从数据库中查询，可以看到SQL执行的日志，结果会进入缓存
        System.out.println(student1.getSname());
        System.out.println("------------------------------------");
        Student student2 = studentMapper.getById("111"); // 从缓存中查询,不会执行SQL语句
        System.out.println(student2.getSname());

        // 执行删除，但是flushCache=false不清空缓存
        studentMapper.deleteStudent("111");
        sqlSession.commit();
        System.out.println("删除成功，但是flushcase=false");

        Student student3 = studentMapper.getById("111");
        System.out.println("删除之后的查询："+student3.getSname());

        Student student4 = new Student("111", "hanliang", "123456", "1", "java01");
        studentMapper.insertStudent(student4);
        sqlSession.commit();
    }

}
